import { createSlice } from '@reduxjs/toolkit';

export interface UserInfoT {
    userId: string | number
    userName: string
    userIp: string
    isLogin: boolean
}
const initialState: UserInfoT = {
    userId: 0,
    userName: 'cxk',
    userIp: '未知',
    isLogin: false,
}
//创建一个slice
export const user = createSlice({
    name: 'user',
    initialState,
    reducers: {
        setUserInfo(state, { payload }) {
            state.userId = payload.userId
            state.userName = payload.userName
        },
        setUserIp(state, { payload }) {
            state.userIp = payload.userIp
        },
        setLogin(state, { payload }) {
            state.isLogin = payload.isLogin
        }
    }
})

//导出方法reducers
export const { setUserInfo, setUserIp, setLogin } = user.actions

//默认导出
export default user.reducer
